package cn.tianyigps.tianyigpsapiv2.config;

import com.mongodb.ReadPreference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;


/**
 * Created with IDEA
 * author:guibin.cui
 * Date:2018/12/20
 * Time:11:37
 *
 */
//@Configuration
public class MongoTemplateConfig {

    @Autowired
    private MongoDbFactory mongoDbFactory;

    @Bean
    public MongoTemplate mongoTemplate() throws Exception {
        MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
        //读写分离配置
        mongoTemplate.setReadPreference(ReadPreference.secondary());
        return mongoTemplate;
    }
}
